<template>
      <div class="container">
        <div class="login-wrapper">
            <div class="header">Login</div>
            <div class="form-wrapper">
                <input type="text" v-model="ruleForm.loginName" name="username" placeholder="username" class="input-item">
                <input type="password" name="password" v-model="ruleForm.pass" placeholder="password" class="input-item">
                <div class="btn" @click="submitForm">Login</div>
            </div>
        </div>
    </div>
</template>
  
<script setup>
import { reactive, ref } from 'vue'
import { login } from '../service/user';
import { setLocal } from '../utils/help';
import { ElMessage } from 'element-plus'

import router from '../router'

const ruleForm = reactive({
  loginName: '',
  pass: '',
})

const submitForm = () => {
  login({
    "loginName": ruleForm.loginName,
    "password": ruleForm.pass
  }).then(res => {
    if (res.resultCode === 200) {
      setLocal('token', res.data.token)
      router.push('/')
    } else {
      ElMessage.error("账号密码错误")
    }
  })
}
</script>

<style scoped>
* {
    margin: 0;
    padding: 0;
}
.container {
    height: 900px;
    background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
}
.login-wrapper {
    background-color: #fff;
    width: 358px;
    height: 588px;
    border-radius: 15px;
    padding: 0 50px;
    position: relative;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.header {
    font-size: 38px;
    font-weight: bold;
    text-align: center;
    line-height: 200px;
}

.input-item {
    display: block;
    width: 100%;
    margin-bottom: 20px;
    border: 0;
    padding: 10px;
    border-bottom: 1px solid rgb(128, 125, 125);
    font-size: 15px;
    outline: none;
}

.input-item:placeholder {
    text-transform: uppercase;
}

.btn {
    text-align: center;
    padding: 10px;
    width: 100%;
    margin-top: 40px;
    background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
    color: #fff;
}
a {
    text-decoration-line: none;
    color: #abc1ee;
}
</style>
